package aws.datameer.awstasks;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class IPAddress {
	
	public String returnIPAddr(int i) throws IOException
	{
		
		Runtime rt = Runtime.getRuntime();
		String cmd = "/home/varsha/./command" + i + ".sh" ;
		String filename = "/var/tmp/output" + i +".txt" ; 
	    Process proc = rt.exec(cmd);
	    File file = new File(filename);
        InputStream input = proc.getInputStream();
        InputStreamReader isr = new InputStreamReader(input);
        BufferedReader br = new BufferedReader(isr);
        BufferedWriter writer = new BufferedWriter(new FileWriter(file,true));
        String line = null;
        while ( (line = br.readLine()) != null)
        {
            //System.out.println(line);
            writer.write(line);
            writer.newLine(); 
            if(i==3)
            {
            	return line ; 
            }
        }
        writer.close();
	    
	    
	    return "" ; 
	}
	
		
	

}
